;
; File xfer script for PCBSuperScript
;
  FIELDS
    Op        .                             C
    Name      ............                  C
    Directory .........................     C
    XferFile  ............................................     C
    DszLog    ..............................................................  C
    DszShell  ..............................................................  C
    DszRShell ..............................................................  C
    DszSShell ..............................................................  C
    FileData  ..............................................................  C
    FMask     ..............................................................  C
  FIELDS

  BEEPS OFF                               ;turn beeps off
  PARSE @%PCBDOOR
  GETWORD Op
  IF Op == "*EOL*"
    SET Op
    GOTO NxtFile
  ENDIF

  GETWORD Directory
  IF Directory == "*EOL*"
    SET Directory
    GOTO NxtFile
  ENDIF

  GETWORD Name
  IF Name == "*EOL*"
    SET Name
    GOTO NxtFile
  ENDIF
  GOTO JumpIn

:NxtFile
  NEWLINE
  NEWLINE
  SET Op                                  ;set var "Op" to null
  COLOR BRIGHT WHITE BLACK                ;set crt color
  PROMPT "Upload, Download or Quit: " Op  ;prompt user for option
  UCASE Op                                ;force "Op" to upper case
  SWITCH  Op                              ;test var "Op"
    CASE  "Q"                             ;quit
      GOTO AbortJob                       ; exit script
      BREAK                               ;
    CASE  "U"                             ;upload
      BREAK                               ;
    CASE  "D"                             ;download
      BREAK                               ;
    CASE                                  ;default processing
      TEXT "Invalid option - try again"   ;display msg to user
      GOTO NxtFile TOP                    ;get option
      BREAK                               ;
  SWITCH  END                             ;

  PROMPT "             File Name: " Name        ;get file name
  NULL_ENTRY  NxtFile                           ;if null, get option
  PROMPT "             Directory: " Directory   ;get dir name
  NULL_ENTRY  NxtFile                           ;if null, get option

:JumpIn
  UCASE Name                          ;set "Name" to upper case
  UCASE Directory                     ;set "Directory" to upper case
  SET   XferFile  Directory "\" Name  ;set xfer file name to dir+'\'+name
  IF Op == "D"
    IF "*" !? XferFile                ;is "*" in the file name?
      IF XferFile !EXIST              ;nope - does it exist?
        TEXT "File " XferFile " does not exist."
        GOTO NxtFile                  ;try again...
      ENDIF
    ENDIF
  ENDIF

  SET   DszLog    "DSZLOG=" Directory @firstu@ ".log"
  SET   DszRShell " port " @port@ " ha bo z rz -mrr " Directory
  SET   DszSShell " port " @port@ " ha bo z sz " XferFile

  IF @graphics@ == "1"            ;not really needed since the following two
    CLEARCRT                      ; commands have 0 effect on no-graphics
    GOTORC 22 1
  ENDIF

  ESET  DszLog                    ;set env var for DSZ to log errors
  SHELL "del " @%DSZLOG           ;delete the log file (in case it exist)

  COLOR BRIGHT CYAN BLACK         ;set crt color
  NEWLINE                         ;print a blank line
  INDENT  5                       ;
  SWITCH  Op                      ;what option?
    CASE  "D"                     ;download requested..
      SET DszShell DszSShell      ;set shell command value to dsz send
      TEXT "@X08" "----------------------------------------------------------------"
      TEXT "@X1B" "               Prepare to receive file now...                   " "@X00"
      TEXT "@X08" "----------------------------------------------------------------"
      BREAK
    CASE  "U"                     ;upload requested..
      SET DszShell DszRShell      ;set shell command value to dsz recv
      TEXT  "@X08" "----------------------------------------------------------------"
      TEXT  "@X1B" "                   Send the file now...                         " "@X00"
      TEXT  "@X08" "----------------------------------------------------------------"
      BREAK
  SWITCH  END
  INDENT  0

  TEXT  DszShell
  SHELL j:\pcb\DSZ.com DszShell   ;do the xfer

  IF @%DSZLOG EXIST               ;if the dsz log file exists,
    NEWLINE                       ; print a blank line,
    COLOR BRIGHT RED BLACK        ; set crt color,
    DISPLAY_FILE @%DSZLOG         ; display the DSZ error log file
  ENDIF                           ;

  IF @%PCBDOOR != ""
    GOTO AbortJob
  ENDIF
  GOTO NxtFile                    ;get next option

:AbortJob
  EXIT
